import {
  createRouter,
  createWebHistory,
  RouteRecordRaw,
  createWebHashHistory,
  Router,
} from "vue-router";
import Layout from "@/layout/index.vue";

// 引入组件
import errorRouter from "./modules/error";
import systemRouter from "./modules/system";
import inwarehouseRouter from "./modules/inwarehouse";
import purchaseRouter from "./modules/purchase";
import inRouter from "./modules/in";
import saleRouter from "./modules/sale";
import outRouter from "./modules/out";

interface extendRoute {
  hidden?: boolean;
}

/**
 * alwaysShow 如果设置为true，将始终显示根菜单，无论其子路由长度如何
 * hidden 如果“hidden:true”不会显示在侧边栏中（默认值为false）
 * keepAlive 设为true 缓存
 */

export const constantRoutes: Array<RouteRecordRaw & extendRoute> = [
  {
    path: "/login",
    name: "Login",
    component: () => import("@/views/login/index.vue"),
    hidden: true,
  },

  // {
  //   path: "/",
  //   name: "index",
  //   component: Layout,
  //   redirect: "/index",
  //   children: [
  //     {
  //       path: "/index",
  //       component: () => import("@/views/dashboard/index.vue"),
  //       name: "index",
  //       meta: {
  //         title: "首页",
  //         icon: "HelpFilled",
  //         affix: true,
  //         role: ["other"],
  //       },
  //     },
  //   ],
  // },

  {
    path: "/",
    name: "index",
    component: Layout,
    redirect: "/index",
    children: [
      {
        path: "/index",
        component: () => import("@/views/screen/titleFirst.vue"),
        name: "index",
        meta: {
          title: "首页",
          icon: "HelpFilled",
          affix: true,
          role: ["other"],
        },
      },
    ],
  },

  {
    path: "/screenMap",
    name: "screenMap",
    component: () => import("@/views/screen/index.vue"),
    // redirect: "/home",
    hidden: true,
    // children: [
    //   {
    //     path: "/home",
    //     name: "home",
    //     component: () => import("@/views/screen/home.vue")
    //   },
    //   {
    //     path: "/openChange",
    //     name: "openChange",
    //     component: () => import("@/views/screen/openChange.vue")
    //   }
    // ],
  },
  {
    path: "/openChange",
    name: "openChange",
    component: () => import("@/views/screen/open.vue"),
    hidden: true,
  },
  {
    path: "/change",
    name: "change",
    component: () => import("@/views/screen/change.vue"),
    hidden: true,
  },
];

// 异步组件
export const asyncRoutes = [
  ...purchaseRouter,
  ...inRouter,
  ...saleRouter,
  ...outRouter,
  ...inwarehouseRouter,
  ...systemRouter,
  errorRouter,
  {
    path: "/:pathMatch(.*)",
    redirect: "/error/404",
  },
];

const router = createRouter({
  // history: createWebHistory(process.env.BASE_URL), // history
  history: createWebHashHistory(), // hash
  routes: constantRoutes,
});

export default router;
